package com.xand.bt.terminal.market;

import com.xand.bt.terminal.common.util.NumberHelper;
import com.xand.bt.terminal.util.BitcoinTerminalConst;

public class MarketLevel implements Comparable<MarketLevel> {

	private long price;

	private long volume;

	private int direction;

	private String reference;

	public MarketLevel(String reference, long price, long volume, int direction) {

		this.reference = reference;
		this.price = price;
		this.volume = volume;
		this.direction = direction;

	}

	public void setVolume(long volume) {
		this.volume = volume;
	}

	public String getReference() {
		return this.reference;
	}

	public long getPrice() {
		return price;
	}

	public long getVolume() {
		return volume;
	}

	public int getDirection() {
		return this.direction;
	}

	public String toString() {

		StringBuilder ret = new StringBuilder("MarketLevel - [");

		ret.append("reference=");
		ret.append(reference);
		ret.append(";");

		String sDirection = "";
		if(this.direction == BitcoinTerminalConst.MARKET_LEVEL_DIRECTION_ASK) {
			sDirection = "ASK";
		}else{
			sDirection = "BID";
		}

		ret.append("direction=");
		ret.append(sDirection);
		ret.append(";");

		ret.append("price=");
		ret.append(NumberHelper.formatLong(this.price, 1000000, 6));
		ret.append(";");

		ret.append("volume=");
		ret.append(NumberHelper.formatLong(this.volume, 100000000, 8));

		ret.append("]");

		return ret.toString();
	}

	public int compareTo(MarketLevel test) {

		int ret = 0;

		if(direction == BitcoinTerminalConst.MARKET_LEVEL_DIRECTION_ASK) {

			if(test.getPrice() > this.price) {
				ret = -1;
			}else{
				ret = 1;
			}

		} else {

			if(test.getPrice() > this.price) {
				ret = 1;
			}else{
				ret = -1;
			}

		}

		return ret;
	}

}
